package com.sunshine.springboot.controller.validate;

import com.sunshine.springboot.bean.Book;
import lombok.extern.slf4j.Slf4j;
import org.hibernate.validator.constraints.Length;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotBlank;

/**
 * spring boot 数据验证
 *
 * @author WeiHong
 * @date 2018/8/23
 */
@RestController
@RequestMapping("validate")
@Validated
@Slf4j
public class ValidateController {

    @PostMapping("test1")
    public String test1(@NotBlank(message = "name 不能为空") @Length(min = 2, max = 10, message = "name 长度必须在 {min} - {max} 之间") String name) {
        return name;
    }

    @PostMapping("test2")
    public String test2(Book book){
        return book.toString();
    }

}
